package com.feihong.txgw.ui.activity.kaika;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.webkit.JavascriptInterface;

import com.feihong.txgw.app.App;
import com.just.agentweb.AgentWeb;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Iterator;

/**
 * Created by Sabirjan on 2017/7/6.
 * TXGWApp.
 * 飞宏电子
 */

public class Step4Interface {

    private AgentWeb agent;
    private Context context;
    private String iccid = "";
    private String phonenum = "";
    private String taocanJSon = "";
    private KaiKaStep4Activity.ActionCallBack callBack;

    public Step4Interface(AgentWeb agent, Context context, String iccid, String phonenum, String taocanJSon, KaiKaStep4Activity.ActionCallBack callBack) {
        this.agent = agent;
        this.context = context;
        this.iccid = iccid;
        this.phonenum = phonenum;
        this.taocanJSon = taocanJSon;
        this.callBack = callBack;
    }

    private Handler deliver = new Handler(Looper.getMainLooper());

    /**
     * 活体检测接口
     *
     * @param cardinfo
     */
    @JavascriptInterface
    public void huotijiance(final String cardinfo) {

      //  Log.i("JS", "身份证数据: " + cardinfo);
        deliver.post(new Runnable() {
            @Override
            public void run() {
         //       Log.i("Info", "main Thread:" + Thread.currentThread());
                callBack.huotijiance(cardinfo);
            }
        });
    }

    /**
     * 提交订单接口
     */
    @JavascriptInterface
    public void tijiaodingdan() {

        deliver.post(new Runnable() {
            @Override
            public void run() {
              //  Log.i("Info", "main Thread:" + Thread.currentThread());
                callBack.tijiaoDingDan();
            }
        });
    }

    /**
     * 加密人脸识别图片
     * @param json
     * @return
     */
    @JavascriptInterface
    public void getParams(final String json) {
//
//        HashMap<String, String> params = new HashMap<>();
//        try {
//            JSONObject jsonparams = new JSONObject(json);
//            Iterator<String> maps = jsonparams.keys();
//            while (maps.hasNext()) {
//                String key = maps.next();
//                String val = jsonparams.getString(key);
//                //url = url + "&" + key + "=" + val;
//                params.put(key, val);
//            }
//        } catch (Exception ex) {
//        }
//        String getparams = App.getApp().getTokenUtils().setSigen(params);
//        App.getApp().getHttpTools().kaikaFaceBaseImg(json,)
        deliver.post(new Runnable() {
            @Override
            public void run() {
                callBack.getParams(json);
            }
        });
    }

    @JavascriptInterface
    public void yuyue_order(final String json){
        deliver.post(new Runnable() {
            @Override
            public void run() {
                callBack.yuyueOrder(json);
            }
        });
    }

    /**
     * 身份证拍照
     */
    @JavascriptInterface
    public void Android_shoot_card(){
        deliver.post(new Runnable() {
            @Override
            public void run() {
                callBack.idCardCamera();
            }
        });
    }

}
